package edu.sctu.zhengsenwen.month201506.day20150614.textthreadutil;

import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * Created by user15 on 2015/6/14.
 */

//继承标签类及应用Runnable接口
public class ClockLabel extends JLabel implements  Runnable {

    private Thread clockThread = null;

    public ClockLabel(){

        if(clockThread == null){

            clockThread = new Thread(this,"clock");

            clockThread.start();
        }

    }



    public void run(){

        while(true){

            Date date = new Date();

            SimpleDateFormat simpleDateFormat = (SimpleDateFormat) SimpleDateFormat.getInstance();

            try{

                this.setText(simpleDateFormat.format(date));

            }catch(
                    Exception e

                    ){

            }
        }
    }

}
